<?php

class myProductRouter  extends myCategoryRouter implements AppRoutingDesc{
	
	private $product = false;
	
	protected function getObjectsForParameters($parameters){
		print_r($parameters);
		exit;
		//return new Doctrine_Collection('Structure','id');
	}
	
	public function getProductObject(){

		

		if(!$this->product){
			$params = $this->getParameters();



			if(isset($params['product_slug'])){
                // Getting product id
				$q = Doctrine::getTable('Product')->createQuery()
                            ->select('id')
							->from('Product p')
							->innerJoin('p.Translation pt')
                            ->where('pt.slug = ?', array($params['product_slug']))
                            ->execute()
                            ->getFirst();

                // Getting the slide
                $slide = Doctrine::getTable('ProductPictures')->createQuery('ps')
                        ->where('ps.product_id=?', array($q->getId()))
                        ->andWhere('ps.pri=?', array(sfContext::getInstance()->getRequest()->getParameter('slide', 1)))
                    	->execute()
                		->getFirst();

				if(!$slide && sfContext::getInstance()->getRequest()->getParameter('slide', 1) > 1) {
					$slide = LinkGen::getInstance(LinkGen::PRODUCT_GROUP)->link($this->getCategoryObject()->getId());
				}
				
				$this->slide   = $slide;
                $this->product = $q;
			}else{
				$this->product = false;
                $this->slide   = false;
			}
		}
		
		return array(
            'product' => $this->product,
            'slide'   => $this->slide
        );
	}
}